package org.example.controller;

import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.example.domain.ResponseResult;
import org.example.domain.dto.CommentListDto;
import org.example.domain.entity.Comment;
import org.example.enums.AppHttpCodeEnum;
import org.example.exception.SystemException;
import org.example.service.CommentService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final CommentService commentService;


    @PostMapping("/sendComment")
    public ResponseResult sendComment(@RequestBody Comment comment) {
        String content = comment.getContent();
        if(StringUtils.isBlank(content)){
            throw new SystemException(AppHttpCodeEnum.NOT_COMMENT_CONTENT_ERROR);
        }
        return commentService.sendComment(comment);
    }

    @PostMapping("/getCommentList")
    public ResponseResult getCommentList(@RequestBody CommentListDto commentListDto){

        return commentService.getCommentList(commentListDto);

    }

    @PutMapping("/deleteComment/{id}")
    public ResponseResult deleteComment(@PathVariable Integer id){

        return commentService.deleteComment(id);
    }
}
